package com.neuedu.web.controller;

import com.neuedu.web.po.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 金山
 * 项目：javaweb
 * site: https://blog.fulfill.com.cn
 *
 *   http://127.0.0.1:8080/web/user_list
 *
 *
 * 描述
 * @data 2024/11/149:51
 */
@WebServlet(urlPatterns = "/user_list")
public class UserListServlet  extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //需要 设置contentType  告诉浏览器  媒体类型 MIME 类型

        //告诉浏览器输出 html
        resp.setContentType("text/json;charset=utf-8");


        //假如从数据库查询出来内容
        // List userList = null;

        User user = new User("100","admin","1234856");
        String json = "{       \"userId\":"+user.getUserId()+",   \"username\":\""+user.getUsername()+"\",  \"password\":\""+user.getPassword()+"\"               }";




        PrintWriter out = resp.getWriter();

        out.write(json.toString());

        out.flush();
        out.close();
    }
}
